if exists (select * from dbo.sysobjects where name='sp_AddLop')
begin
	Drop Proc sp_AddLop
end
go
create proc sp_AddLop
@MALOP VARCHAR(40),
@TENLOP NVARCHAR(40),
@MAKHOA NVARCHAR(40),
@TENKHOA NVARCHAR(40),
@USER1 VARCHAR(40),
@USER2 VARCHAR(40),
@USER3 VARCHAR(40),
@USER4 VARCHAR(40),
@USER5 VARCHAR(40),
@KQ INT OUTPUT
as 
begin 
	SET @KQ=0
	IF NOT EXISTS (SELECT * FROM SINHVIEN WHERE TENLOP=@TENLOP)
	BEGIN
		INSERT INTO LOP VALUES(@MALOP,@TENLOP,@MAKHOA,@TENKHOA,@USER1,@USER2,@USER3,@USER4,@USER5)
		SET @KQ=1
	END
END

DECLARE @KQ INT
EXEC sp_AddLop '001','LAPTRINH','002','CNTT','','','','','',@KQ OUTPUT
SELECT @KQ AS KQ